<?php

namespace app\api\controller\qsy;


use app\admin\controller\activity\Subject;
use app\admin\model\activity\ActivityType;
use app\admin\model\activity\ProjectActivity;
use app\admin\model\activity\SubjectActivity;
use app\admin\model\qsy\Banner;
use app\admin\model\qsy\Indexbanner;
use app\admin\model\qsy\Story;
use app\admin\model\spots\ScenicSpots;
use app\admin\model\wanlshop\Shop;
use app\common\controller\Api;
use app\common\handler\TimeHandler;
use app\common\helpers\ImageUtil;
use app\common\model\Config;
use think\Model;

/**
 * 周边景点
 */
class Spots extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];



    //列表
    public function list()
    {
        $page = $this->request->param('page',1);//页码
        $pageSize = $this->request->param('pageSize',10);//每页展示数量
        $type = $this->request->param('type');//类型   游点不一样 = point 热门推荐top
        $search = $this->request->param('search');//搜索
        $where = [
            'a.status'=> '1' ,
            's.status'=> 'normal',
        ];
        if($type == 'point'){
            $where['is_point'] = 1;
        }
        if($type == 'top'){
            $where['is_top'] = 1;
        }
        if($search){
            $where['title'] = ['like','%' .$search. '%'];
        }
        $model=(new ScenicSpots())->alias('a')
            ->field('a.id,cover_img,label,shopname,title,sketch')
            ->join('wanlshop_shop s','s.id = a.shop_id','left')
            ->where($where)
            ->order('create_time desc')
            ->paginate($pageSize, '', ['page' => $page, 'list_rows' => $pageSize]);
        $total= $model->total();
        $list =  $model->items();
        if($list){
            foreach ($list as $v){
                $v['cover_img'] = ImageUtil::handle($v['cover_img']);
                $v['labelAll'] = !in_array($v['label'],["",null]) ? explode(',',$v['label']) : [];
            }
        }
        $result = array("total" =>$total , "list" => $list);
        $this->success("获取成功",$result);
    }


    //周边详情
    public function  spotsDetails(){
        $id = $this->request->param('id');
        $info = ScenicSpots::field('id,title,label,cover_img,content,address,lng,lat')->where('id',$id)->find();
        if($info){
            $info['cover_img'] = ImageUtil::handle($info['cover_img']);
            $info['labelAll'] = !in_array($info['label'],["",null]) ? explode(',',$info['label']) : [];
            $this->success('获取成功', $info);
        }
        $this->error('不存在');
    }

}
